package com.ruoyi.web.controller.job;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.job.domain.JobInfo;
import com.ruoyi.job.service.IJobInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 兼职详情Controller
 * for student
 * 学生可以查看所有的兼职信息
 * @author ace
 * @date 2020-02-02
 */
@Controller
@RequestMapping("/job/info4Student")
public class JobInfo4StudentController extends BaseController {
    private String prefix = "job/student";

    @Autowired
    private IJobInfoService jobInfoService;

    @RequiresPermissions("job:info4stu:view")
    @GetMapping("/info")
    public String info2() {
        return prefix + "/info4Student";
    }

    /**
     * 查询兼职详情列表
     */
    @RequiresPermissions("job:info4stu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JobInfo jobInfo) {
        startPage();
        List<JobInfo> list = jobInfoService.selectJobInfoList(jobInfo);
        return getDataTable(list);
    }


    /**
     * 评价兼职 for student
     */
    @GetMapping("/edit/{jobInfoId}")
    public String edit(@PathVariable("jobInfoId") Long jobInfoId, ModelMap mmap) {
        //TODO 查询兼职评价表
        JobInfo jobInfo = jobInfoService.selectJobInfoById(jobInfoId);
        mmap.put("jobInfo", jobInfo);
        return prefix + "/edit4Student";
    }

    /**
     * 修改评价兼职 for student
     */
    @RequiresPermissions("job:info4stu:opinion")
    @Log(title = "兼职详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JobInfo jobInfo) {
        //TODO 修改兼职评价表
        Long userId = ShiroUtils.getSysUser().getUserId();
        jobInfo.setUpdatedBy(userId);
        jobInfo.setUpdatedTime(System.currentTimeMillis());
        return toAjax(jobInfoService.updateJobInfo(jobInfo));
    }
}
